package aden.SifWar.EvtLog;

import java.io.IOException;

import aden.Generic.Gen2DPoint;
import aden.Generic.Param.GenParamData;
import aden.Generic.Param.GenParamException;
import aden.Generic.Param.GenParamInt;
import aden.Generic.Param.GenParamIter;
import aden.Generic.Param.GenParamNode;
import aden.SifWar.SifWarUnit;


public class SifWarEvtLogEndureDamage extends SifWarEvtLog
{
	public SifWarEvtLogEndureDamage(SifWarEvtLogMgr inMgr,
			                Gen2DPoint      inUnit,
			                Gen2DPoint      inSource,
			                int      inDamageAmount,
			                int      inDamageType)
	{
		super(inMgr);
		mUnit = inUnit;
		mSource = inSource;
		mDamageAmount   = inDamageAmount;
		mDamageType = inDamageType;
	}
		
	public boolean Process()
	{
		SifWarUnit theUnit = mMgr.GetPlayerMgr().FindUnit(mUnit);
		theUnit.RealEndureDamage(mDamageAmount,mDamageType,mSource);
		return true;
	}

	public boolean Export(GenParamNode inNode)
	{
		if (!inNode.Add(new GenParamInt("UX",mUnit.GetX())) ||
			!inNode.Add(new GenParamInt("UY",mUnit.GetY())) ||
			!inNode.Add(new GenParamInt("SX",mSource.GetX())) ||
			!inNode.Add(new GenParamInt("SY",mSource.GetY())) ||
			!inNode.Add(new GenParamInt("A",mDamageAmount)) ||
			!inNode.Add(new GenParamInt("T",mDamageType)))
		{
			return false;
		}
		return true;
	}

	public boolean Import(GenParamIter inIter)
	{
		try
		{
		   mUnit.SetX(inIter.GetNextIntContent());
		   mUnit.SetY(inIter.GetNextIntContent());
		   mSource.SetX(inIter.GetNextIntContent());
		   mSource.SetY(inIter.GetNextIntContent());
		   mDamageAmount = inIter.GetNextIntContent();
		   mDamageType = inIter.GetNextIntContent();
		}
		catch (GenParamException e) 
		{
			return false;
		}
		return true;
	}
	
	public String GetDesc()
	{
		return "Endure damage at ("+Integer.toString(mUnit.GetX())+","+Integer.toString(mUnit.GetX())+") with "+
	           Integer.toString(mDamageAmount)+","+Integer.toString(mDamageType)+
	           " from ("+Integer.toString(mSource.GetX())+","+Integer.toString(mSource.GetX())+")";
	}
	
	private Gen2DPoint mUnit;
	private Gen2DPoint mSource;
	private int mDamageAmount;
	private int mDamageType;

}
